<template>
  <j-modal
    title="处置"
    :width="600"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="formRef" :rules="rules" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item label="处置内容" prop="content">
          <a-textarea
            class="input"
            v-model="form.content"
            placeholder="请输入"
            :auto-size="{ minRows: 4, maxRows: 6 }"
            allow-clear
          />
        </a-form-model-item>
      </a-form-model>
    </a-spin>
    <template slot="footer">
      <a-button key="back" @click="handleCancel">取消</a-button>
      <a-button key="submit" type="primary" @click="handleOk">确定</a-button>
    </template>
  </j-modal>
</template>

<script>
import * as alarmApi from '@/api/xlgc/alarmCenter.js'
import CustomTable from '@/components/zxd/Table/CustomTable'
export default {
  name: 'DisposeModal',
  components: {
    CustomTable
  },
  props: {
    id: {
      type: [String, Number]
    }
  },
  data() {
    return {
      visible: false,
      disableSubmit: false,
      form: {},
      labelCol: { span: 6 },
      wrapperCol: { span: 16 },
      rules: {
        content: [
          { required: true, message: '请填写处置说明', trigger: 'change' },
          { min: 1, max: 150, message: '处置内容最多填写150字', trigger: 'change' }
        ]
      },
      confirmLoading: false
    }
  },
  computed: {},
  methods: {
    show() {
      this.visible = true
      this.form = {}
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.formRef.validate(valid => {
        if (valid) {
          this.confirmLoading = true
          this.form.ids = [this.id]
          alarmApi
            .personnelDispose(this.form)
            .then(res => {
              if (res.success) {
                let message = res.message ? res.message : '操作成功'
                this.$message.success(message)
                this.visible = false
                this.confirmLoading = false
                this.$emit('ok')
              } else {
                this.confirmLoading = false
                this.$message.warn(res.message)
              }
            })
            .catch(e => {
              this.confirmLoading = false
              this.$message.warn('操作失败！')
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>
<style lang="less" scoped></style>
